﻿import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	private static ArrayList<Student> studentList = new ArrayList<>();
	private static ArrayList<Course> courseList = new ArrayList<>();
	private static ArrayList<Class1> classList = new ArrayList<>();
	private static ArrayList<Score> scoreList = new ArrayList<>();
	static boolean isMenuShow=false;
	public static void main(String[] args){
		showMenu();
	}

	private static void showMenu() {
		while(true){
		// 为了避免程序疯狂运行造成死机 
		// 每秒钟检查一次是否要展示菜单
			try{
				Thread.sleep(1000);
			}catch(InterruptedException e){
				e.printStackTrace();
			}
			if(!isMenuShow){
				PrintUtil.printMenu(null);
				isMenuShow=true;
				
				Scanner sc=new Scanner(System.in);
				int i;
				try{
					i=sc.nextInt();
					switch(i){
					case 1:
					   studentList = StudentDao.queryStudentList();
					  PrintUtil.print(studentList);
					   break;
					case 2:
						courseList = CourseDao.queryCourseList();
						PrintUtil.print1(courseList);
						break;
					case 3:
						classList = ClassDao.queryclassList();
						PrintUtil.print2(classList);
						break;
					case 4:
						scoreList = ScoreDao.queryScoreList();
						PrintUtil.print3(scoreList);
						break;
					case 5:
						// 获取学生信息
						Student student=getStudentInfo();
						// 添加学生
//						StudentDao.addUseStatement(student);
						StudentDao.addUsePrepareStatement(student);
						break;
				    case 6:
				    	// 获取用户输入的学生姓名
						String name = getStudentName();
						// 按照姓名删除学生 
						StudentDao.del(name);
						break;
					case 7:
						// 退出程序
						System.exit(0);
						break;
						default:
					System.out.println("你的输入有误，请重新输入");
					break;
					}
				}catch(Exception e){
					System.out.println("你的输入有误，请重新输入");
				}
				isMenuShow=false;
		  }
		}
	}
	private static String getStudentName() {
		Scanner in = new Scanner(System.in);
		System.out.println("请输入姓名");
		String name = in.nextLine();
		return name;
	}

	private static Student getStudentInfo() {
		Scanner in=new Scanner(System.in);
		System.out.println("请输入学号");
		int id=in.nextInt();
		
		in =new Scanner(System.in);
		System.out.println("请输入姓名");
		String name=in.nextLine();
		
		in =new Scanner(System.in);
		System.out.println("请输入年龄");
		int age=in.nextInt();
		
		in =new Scanner(System.in);
		System.out.println("请输入班级名称");
		String bjmc=in.nextLine();
		
		in =new Scanner(System.in);
		System.out.println("请输入专业");
		String zy=in.nextLine();
		
		in = new Scanner(System.in);
		System.out.println("请输入性别");
		String sex = in.nextLine();
			
		System.out.println("学生信息输入完成");
		
		// 智能提示自动完成   ALT+？
		Student student =  new Student(id, name, age, bjmc, zy, sex);
		return student;

	}
	
		
}

